/**
 * Created by baidm in 2022/4/17 on 20:23
 */
export default function (src) {
    return new Promise((resolve) => {
        let canvas = document.createElement('canvas');
        canvas.width = 200;
        canvas.height = 200;
        let context = canvas.getContext('2d');
        let img = new Image()
        img.crossOrigin = 'Anonymous';
        img.src = src
        img.onload = () => {
            //开始路径画圆,剪切处理
            context.save();
            context.beginPath();
            context.arc(100, 100, 100, 0, Math.PI * 2);
            context.clip(); //剪切路径
            context.drawImage(img, 0, 0, 200, 200);
            //恢复状态
            context.restore();
            let dataURL = canvas.toDataURL('image/png');
            resolve(dataURL)
        }
    })
}